package com.example.eurekaconsumer.controller;

import com.example.eurekaconsumer.service.FeignTestService;
import com.example.eurekaconsumer.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Date: 2021/2/19 10:57
 * @Author: yulei
 * @Description:
 */
@Controller
@RequestMapping("/Index")
public class IndexController {
    @Autowired
    private Environment env;

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private FeignTestService feignTestService;
    /**
     * FEIGN 测试
     */
    @RequestMapping("/hello")
    public String hello() {
        feignTestService.hello();
        return "index";
    }

    /**
     * 首页
     *
     * @param model
     * @return
     */
    @RequestMapping("index")
    public String index(Model model) {
//        List list = restTemplate.getForObject("http://"+ env.getProperty("producer.name")+"/Index/index", List.class);
        List list = feignTestService.Index();//FEIGN调用
        model.addAttribute("title", "首页");
        model.addAttribute("goods", list);
        return "index";
    }

    /**
     * 首页精品推荐
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/boutique")
    public String boutique(HttpServletRequest request, Model model) {
        List list = sysUserService.getList(request, "");
        model.addAttribute("keywords", (request.getParameter("keywords")) == null ? "" : request.getParameter("keywords"));
        model.addAttribute("title", "列表");
        model.addAttribute("goods", list);
        return "goods/pro_list";
    }

}
